package com.sk.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//面相切面编程
@Slf4j
@Aspect
//@Component
public class AspectDemo {

    @Pointcut("execution(* com.sk.aop.controller.*.*(..))")//声明一个切点
    private void pt(){}//切点名称
    @Before("pt()")
    public void doBefore(){
        log.info("do before...");
    }

    @After("pt()")
    public void doAfter(){
        log.info("do after...");
    }

    @Around("pt()")//优先级比上面两个
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {//此处必须要有返回结果，不然目标方法会没有返回值
        log.info("do around before...");
        Object result = pjp.proceed();
        log.info("do around after...");
        return result;
    }

    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("do AfterReturning...");
    }

    @AfterThrowing("pt()")
    public void doAfterThrowing(){
        log.info("do AfterThrowing...");
    }




}
